package com.baidu.customview.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.AvoidXfermode;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import com.baidu.customview.R;

/**
 * Created by imagine on 2015/11/14.
 */
public class AntiTerroristView extends View {
    private Paint boundPaint;
    private Paint fillPaint;
    private float pointX, pointY;
    private int radius = 70;

    public AntiTerroristView(Context context) {
        super(context);
        init();
    }

    private void init() {
        boundPaint=new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DITHER_FLAG);
//        boundPaint.setStyle(Paint.Style.FILL_AND_STROKE);//设置成该属性或者fill属性后，再设置strokeWidth就没效果了
//        boundPaint.setStrokeWidth(5);
//        boundPaint.setColor(getResources().getColor(R.color.orange));
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.peien);
        boundPaint.setShader(new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
        fillPaint=new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DITHER_FLAG);
        fillPaint.setStyle(Paint.Style.FILL);
        fillPaint.setColor(getResources().getColor(R.color.black));
    }

    public AntiTerroristView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public AntiTerroristView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public AntiTerroristView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(getResources().getColor(R.color.tarmac));
        canvas.drawCircle(pointX, pointY, radius, boundPaint);
        canvas.drawCircle(pointX,pointY,radius-50,fillPaint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        pointX = event.getX();
        pointY = event.getY();
        invalidate();
        return true;
    }
}
